package cn.enn.smart.conf;

import cn.enn.smart.service.UserDetailsServiceExtension;
import cn.enn.smart.service.impl.EnnUserDetailsServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class EnnSecurityAutoConfiguration {

	@Bean
	@ConditionalOnMissingBean(PasswordEncoder.class)
	public PasswordEncoder passwordEncoder() {
		return new BCryptPasswordEncoder();
	}

	@Bean
	@ConditionalOnMissingBean(UserDetailsServiceExtension.class)
	public UserDetailsServiceExtension userDetailsService() {
		return new EnnUserDetailsServiceImpl(passwordEncoder());
	}
}
